package org.sdnstproject.interlayer;

import org.sdnstproject.interlayer.DummyProxyV10.OFFuzzerV10;
import org.sdnstproject.interlayer.interlayerProxy.Configuration;
import org.sdnstproject.interlayer.DummyProxyV13.OFFuzzerV13;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Scanner;

public class Main {
    private static Logger log = LoggerFactory.getLogger(Main.class);
    private static Configuration config = Configuration.getInstance();
    public static final String ANSI_RESET = "\u001B[0m";
    public static final String ANSI_GREEN_B = "\u001B[21;97m";
    public static final String ANSI_GREEN_N = "\u001B[1;92m";
    public static final String ANSI_RED = "\u001B[31m";
    public static final String LOGO =
            "   _______  _  ______\n" +
                    "  / __/ _ \\/ |/ / __/\n" +
                    " _\\ \\/ // /    / _/  \n" +
                    "/___/____/_/|_/_/    \n" +
                    "                     \n";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("\n欢迎使用  ");
        System.out.print(ANSI_RED);
        // System.out.print("\n" + LOGO + "\n");
        System.out.print("SDN安全性测试子系统");
        System.out.print(ANSI_RESET);
        System.out.println("!\n");

        try {
            Runtime.getRuntime().exec("scp " + config.getInterlayer_ROOT() + "pyscript/controllerAgent.py " + config.getControllerSSH() + ":~/");
            Runtime.getRuntime().exec("scp " + config.getInterlayer_ROOT() + "pyscript/switchAgent.py " + config.getSwitchSSH() + ":~/");
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        log.info("starting Test " + config.getTargetController() + " by OpenFlow" + config.getOpenFlowVersion());
        System.out.println("开始测试" + config.getTargetController() + ", OpenFlow版本为" + config.getOpenFlowVersion());
        System.out.println();

        if (config.getOfVersion() == 1) {
            OFFuzzerV10 fuzzerV10 = new OFFuzzerV10();
            fuzzerV10.doOpenFlowFuzzer();
        } else {
            OFFuzzerV13 fuzzerV13 = new OFFuzzerV13();
            log.info("starting Test " + config.getTargetController() + " by OpenFlow1.3");
            fuzzerV13.doOpenFlowFuzzer();
        }
        System.exit(0);
    }

}
